package com.wish.g1.business.listener;

import com.wish.g1.common.core.config.SmsConfig;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.listener.AcknowledgingMessageListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ListenerConsumer implements AcknowledgingMessageListener<String, String> {

    @SneakyThrows
    @Override
    @KafkaListener(topics = {"business"})
    // @KafkaListener(topicPartitions = {@TopicPartition(topic = "topic", partitions = "0")})
    public void onMessage(ConsumerRecord<String, String> consumerRecord, Acknowledgment acknowledgment) {

        System.err.println(consumerRecord.key());
        System.err.println(consumerRecord.value());
        // 提交偏移量
        acknowledgment.acknowledge();

        SmsConfig.send2("15525118214",consumerRecord.value());

    }
}
